package com.lml.service;

import com.lml.bean.Conurses;
import com.lml.bean.Scores;
import com.lml.bean.Xuanke;
import com.lml.dao.IConursesDao;
import com.lml.dao.IScoresDao;
import com.lml.dao.IXuankeDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LgoinImpl implements ILgoin {

    @Autowired
    private IScoresDao sconresDao;

    @Autowired
    private IConursesDao conursesDao;

    @Autowired
    private IXuankeDao xuankeDao;

    @Override
    public Boolean login(String number, String password) {
        try {
            if (number.equals("789789") && password.equals("1472580")) {
                System.out.println("教师用户登录成功");
                System.out.println("查询所有成绩记录");
                List<Scores> allScores = sconresDao.selectAll();
                for (Scores scores : allScores) {
                    System.out.println(scores);
                }
                System.out.println("更新20220102001的数学成绩");
                sconresDao.updateScores(100, "20220102001");
                Scores updatedScore = sconresDao.getScores("20220102001");
                System.out.println(updatedScore);

            } else if (number.equals("20220102001") && password.equals("123456")) {
                System.out.println("学生用户登录成功");
                System.out.println("查询20220102001的成绩记录");
                Scores scores = sconresDao.getScores("20220102001");
                System.out.println(scores);
                System.out.println("查询待选课记录");
                List<Conurses> allConurses = conursesDao.selectAll();
                for (Conurses conurses : allConurses) {
                    System.out.println(conurses);
                }
                System.out.println("更新的选课记录");
                conursesDao.updateConurses(1);
                xuankeDao.updateXuanke("20220102001", 1);
                System.out.println("查询20220102001的选课记录");
                Xuanke xuanke = xuankeDao.getXuanke("20220102001");
                System.out.println(xuanke);

            } else {
                System.out.println("用户名或密码错误");
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
}
